博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP-案例-商品增删改
阅读量:4350 次
发布时间:2019-06-07

本文共 4824 字,大约阅读时间需要 16 分钟。

商品的增删改查

1显示

 

部分代码

Dao

public List
findAllProduct() throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from product"; List
productList = runner.query(sql, new BeanListHandler
(Product.class)); return productList; }

Jsp

${vs.count }
${pro.pname } ${pro.shop_price } ${pro.is_hot==1?"是":"否" }

 

2 增

先获得分类数据

//获得所有的商品的类别数据                  AdminProductService service = new AdminProductService();                  List
categoryList = null; try { categoryList = service.findAllCategory(); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("categoryList", categoryList);

 

在显示类别

 

 

接着做数据库添加操作

public void addProduct(Product product) throws SQLException {                  QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());                  String sql = "insert into product values(?,?,?,?,?,?,?,?,?,?)";                  runner.update(sql, product.getPid(),product.getPname(),product.getMarket_price(),                                            product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),                                            product.getPdesc(),product.getPflag(),product.getCid());                          }

3 删除

分析:你要确定你要删除的是那个,所以你要传参数,来确定你删除的是那个

Pid 来确定

Jsp

                                                                                                                                                                                                                                                                                                                                                                                                              

 

 

JS

  

function delProduct(pid){                                   var isDel = confirm("您确认要删除吗?");                                   if(isDel){                                            //要删除                                            location.href = "${pageContext.request.contextPath}/adminDelProduct?pid="+pid;                                   }                          }

 

 

4 修改

 

比较不好处理的点:商品的分类select 里面的option

1在编辑商品时需要向数据库传递你要更改的那个

2 Select里面的option默认显示是那个;

 需要option里面的value和category里面的cid进行对比(js或者jq)

 

 

Jsp里面的编辑代码

                                                                                                                                                                                                                             

 

 5 源代码

源代码:链接:https://pan.baidu.com/s/1J5u4s3emjlluZIWw7TkZmw 密码:cl9b

 

转载于:https://www.cnblogs.com/liu-wang/p/8612348.html

你可能感兴趣的文章
Nginx配置文件nginx.conf中文详解(总结)
查看>>
Linux的用户态和内核态
查看>>
JavaScript原生错误及检测
查看>>
(原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(3): 深度克隆clone()
查看>>
为什么写作
查看>>
整数子数组求最大和添加验证
查看>>
使用kubeadm安装Kubernetes
查看>>
Principal Component Analysis 主元分析
查看>>
linux分割字符串操作
查看>>
PHP学习2
查看>>
多实例Mysql配置
查看>>
linux下安装Mongodb
查看>>
Page.RegisterStartupScript和Response.Write的区别。
查看>>
hdu4348区间更新的主席树+标记永久化
查看>>
ZOJ 2532 Internship
查看>>
HDU 3452 Bonsai
查看>>
[Erlang12] Mnesia分布式应用
查看>>
图的遍历 | 1013 连通块块数
查看>>
Kinect 开发 —— 进阶指引(上)
查看>>
python学习笔记(六)time、datetime、hashlib模块
查看>>